<?php
/**
 * theme : default
 * description : sidebar-content
 * author : Gmax
 */

//déclaration des variables pour l'affichage de la page
$posts = $this->getPublications();
$category = $this->getCategory();
$article = ($this->getTargetType()==='page'||$this->getTargetType()==='publication')?$this->getTarget():null;
if($this->getTarget()!==null && $this->getTarget()->haveMedia()){
    $topImage = $this->getTarget()->getMedia();
}elseif($category!==null && $category->haveMedia()){
    $topImage = $category->getMedia();
}
?>
<?php if(isset($topImage)&&$topImage!==null&&$topImage->getHeight()>0): ?>
<div class="top-image">
    <img class="banniere" src="<?php echo $topImage->getUrl(); ?>" width="<?php echo $topImage->getWidth(); ?>" alt="<?php echo $topImage->getLegende(); ?>" title="<?php echo $topImage->getTitle(); ?>"/>
</div>
<?php else: ?>
<div class="gabarit-top-image">
    &nbsp;
</div>
<?php endif; ?>
<div class="container hidden">
    <?php echo $this->getBreadcrumb('|'); ?>
</div>
<div class="separateur">&nbsp;</div>
<div id="content" class="container">
     <div class="columns eleven">
        <h1 class="titre gris roboto"><?php echo ($article!==null)?$article->getTitle():$category->getTitle(); ?></h1>
        <?php if(count($posts)>0): ?>
        <?php $i = 1; ?>
        <?php foreach( $posts as $idx=>$oPost ): ?>
        <?php $post = $oPost->getDatas(); ?>
        <div class="columns five menus menu_<?php echo $i; ?>">
            <article id="post_<?php echo $post['id']; ?>"><div class="article">
                <div class="post-content">
                    <h3 class="text-center hidden"><?php echo $post['title']; ?><br/></h3>
                    <?php echo $post['content']; ?>
                </div>
                <div class="clear">&nbsp;</div>
            </div></article>
        </div>
        <?php if($i===2 && ($idx+1)<count($posts)): ?>
        <div class="separateur_menus bg_brun">&nbsp;</div>
        <?php endif; ?>
        <?php $i = ($i===1)?2:1; ?>
        <?php endforeach; ?>
        <?php else: ?>
            <article id="nopost"><div class="article">
                <div class="post-content">
                    Cette rubrique est actuellement en construction.
                </div>
            </div></article>
        <?php endif; ?>
    </div>
    <div class="columns five" itemscope itemtype="http://schema.org/WPSideBar">
        <?php
        $laCarte = modele::findByPermalien('la-carte', 'category');
        if($laCarte !== null){
            $cartes = $laCarte->getChild();
        }else{
            $cartes = array();
        }
        ?>
        <div class="titre gris"><?php echo $laCarte->getTitle(); ?></div>
        <?php if(count($cartes)>0): ?>
        <?php foreach($cartes as $carte): ?>
        <?php if($carte->getNombrePublications(true)>0): ?>
        <h2 class='bleu_gris'><?php echo $carte->getTitle(); ?></h2>
        <table class="grille-prix">
        <?php foreach($carte->getPublications() as $produit): ?>
            <tr>
                <td><?php echo $produit->getTitle(); ?></td>
                <td class="prix"><?php echo $produit->getCustomVar('prix'); ?> &euro; HT</td>
            </tr>
        <?php endforeach; ?>
        </table>
        <?php endif; ?>
        <?php endforeach; ?>
        <?php endif; ?>
        
        <div class="encart-sidebar text-center bg_gris_clair marginTop">
            <h4 class="vert">Découvrez notre<br/>carte des vins</h4>
            <div class="verre" style="margin-top: 2px;margin-bottom: 8px;">&nbsp;</div>
            <p>
                <a href="<?php echo $this->getBaseUrl(); ?>les-vins/" class="vert">> voir la carte</a>
            </p>
        </div>
    </div>
</div>
<?php $cadeau = modele::findByPermalien('idee-cadeau', 'category'); ?>
<?php if($cadeau !== null && $cadeau->getNombrePublications(true)>0): ?>
<div class="separateur">&nbsp;</div>
<div class="container">
    <div class="columns sixteen titre gris"><?php echo $cadeau->getTitle(); ?></div>
</div>
<div id="content" class="container">
    <?php
        $publications = $cadeau->getPublications(0,1,true);
        $publication = $publications[0];
    ?>
    <div class="columns six">
        <?php if($publication->haveMedia()): ?><img src="<?php echo $publication->getMedia()->getUrl(); ?>" width="100%" /><?php endif; ?>
    </div>
    <div class="columns ten">
        <article id="post_<?php echo $publication->getId(); ?>"><div class="article">
            <div class="post-content">
                <h2 class="vert"><?php echo $publication->getTitle(); ?></h2>
                <?php echo $publication->getContent(); ?>
            </div>
        </div></article>
    </div>
</div>
<?php endif; ?>